﻿using Gameplay.PVE;
using UnityEngine;
using Yoozoo.Modules.Update;
using EDeviceGrade = DevicesGrading.DeviceGrade;

namespace Yoozoo.Mars.Got
{
    public partial class DeviceAgent : IDeviceAgent
    {
        private bool isDevicesGradingInit;
        
        public void InitDevicesGrading()
        {
            DevicesGrading.Instance.Init(DeviceQualityChange, LogCallback);
            
            isDevicesGradingInit = true;
        }

        public bool IsDevicesGradingInited()
        {
            return isDevicesGradingInit;
        }

        public void LogCallback(object o)
        {
            if (Debug.unityLogger.logEnabled && o != null)
            {
                Debug.Log(o);
            }
        }

        public void DeviceQualityChange(EDeviceGrade quality)
        {
            if (Debug.unityLogger.logEnabled)
            {
                LogCallback("DevicesGrading>>>:" + quality.ToString());
            }
            //设置当前画质 
            // ??? 怎么两个质量枚举在相互转换
            DeviceQuality.Instance.ChangeQuality((QualityEnum)quality);
        }
        
        public int GetDeviceQuality()
        {
            int nQuality = 0;
            if (DevicesGrading.Instance != null)
            {
                EDeviceGrade quality = DevicesGrading.Instance.DeviceGradeInfo;
                nQuality = (int)quality;
            }

            return nQuality;
        }

        /// <summary>
        /// 返回推荐的图形质量
        /// </summary>
        /// <returns></returns>
        public int GetRecommondDeviceGrade()
        {
            int nGrade = 0;
            if (DevicesGrading.Instance != null)
            {
                EDeviceGrade grade = DevicesGrading.Instance.GetRecommondDeviceGrade();
                nGrade = (int) grade;
            }
            return nGrade;
        }

        public void SetDeviceQuality(int nQuality)
        {
            DeviceQuality.Instance.ChangeQuality((QualityEnum)nQuality);
        }

        public void SetDeviceCommanderHeadShow(bool isShowHead)
        {
            DeviceQuality.Instance.ChangeCommanderHeadShow(isShowHead);
        }
    }
}
